<?php session_start();?>
<!--
To change this template, choose Tools | Templates
and open the template in the editor.
-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
    <head>
        <LINK REL=StyleSheet HREF="maintenancePagesCSS.css" TYPE="text/css" />
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title></title>
    </head>
    <body>
        <center>
        <div class="EditTable" style="width: 95%; height:85%">
            <h2><?php echo $_GET['function']; ?> a Work Log Record</h2>
            <?php
                include "Datasource.php";
                include "WorkDone.php";
                include "WorkDoneDao.php";
                include "EmployeeDAO.php";
                include "Employee.php";
                $conn = new Datasource("localhost", "theanykey", "root", "");
                $objEmpDAO = new EmployeeDao();
                $emp = new Employee();
                $emp = $objEmpDAO->getObject($conn, $_SESSION['userId']);
                $objWdDAO = new WorkDoneDao();
                $objWd = new WorkDone();
                $objWd = $objWdDAO->getObject($conn, $_GET['id']);
                $empAssigned = $objEmpDAO->getObject($conn,  $objWd->getTechAssigned());
                $isEdit = ($_GET['function'] == 'Edit') ? true : false;
                $isView = ($_GET['function'] == 'View') ? true : false;
                if($empAssigned) $empAssnName = $empAssigned->getLastName() . ", " . $empAssigned->getFirstName();
                $hours = $objWd->getHrsWorkDone();
                $notes = $objWd->getNotes();
                $date = $objWd->getDateDone();
                $row = $_GET['row'];
                $id = $_GET['id'];
            if(!$isEdit)
            {
                ?>
                <form id="frmDeleteWdRecord" method="post" action="DeleteWdRecord.php">
                    <input type="hidden" name="wdToDeleteId" <?php echo "value='$id'";?> />
                    <input type="hidden" name="wdToDeleteRowId" <?php echo "value='$row'";?> />
                </form>
            <?php
            }
            else
            {?>
            <form id="frmEditWd" action="EditWorkDoneFunc.php" method="post">
                    <input type="hidden" name="wdToEditId" <?php echo "value='$id'";?> />
                    <input type="hidden" name="wdToEditRowId" <?php echo "value='$row'";?> />
            <?php
                }
                ?>
                <table>
            <tr>
                <th>
                    Tech:&nbsp;
                </th>
                <td>
                    <?php //write tech assigned
                        echo $empAssnName;
                    ?>
                </td>
            </tr>
            <tr>
                <th>
                    Date:&nbsp;
                </th>
                <td>
                    <?php
                    echo $date;
                    ?>
                </td>
            </tr>
            <tr>
                <th>
                    Hours:&nbsp;
                </th>
                <td>
                    <?php //write hours or textbox for editing hours based on functionality
                        if($isEdit)
                        {
                            ?>
                            <input type="text" value="<?php echo $hours;?>" id="wdEditHours" name="wdEditHours" />
                            <?php
                        }
                        else
                        {
                            echo $hours;
                        }?>
                </td>
            </tr>
            <tr>
                <th>
                    Notes:&nbsp;
                </th>
                <td>
                    <?php
                        if($isEdit)
                        {
                            ?>
                    <textarea onkeydown="forceMaxLength();" rows="4" cols="40" id="wdEditNotes" maxlength="1000" name="wdEditNotes"><?php echo $notes;?></textarea>
                               <script type="text/javascript">
                            function forceMaxLength()
                            {
                                var textBox = document.getElementById("wdEditNotes");
                                var maxLength = parseInt(textBox.getAttribute('maxlength'));
                                  if(textBox.value.length > maxlength)
                                  {
                                     textBox.value = textBox.value.substring(0, maxlength);
                                  }
                            }
                               </script>
                        
                            <?php
                        }
                        else
                        {
                            echo $notes;
                        }?>
                </td>
            </tr>
        </table>
            <br/>
            <?php
            if($isEdit)
            {
                ?>
            <input type="button" value="Save" id="btnEditSubmit" onclick="submitEditForm();" />

                <?php
            }
            else
            {
                //its a delete
                if(!$isView)
                {
                        ?>
                    <input type="button" value="Submit" id="btnDeleteSubmit" onclick="submitDeleteForm();" />
                        <?php
                }
            }
            ?>
            &nbsp;
            <input type="button" value="Cancel" onclick="window.close();" />
            <br/>
            <br/>
            </form>
        </div>

    </center>
    </body>
    <script type="text/javascript">
        function submitDeleteForm()
        {
            if(confirm("Are you sure you want to delete this?\n    Ok -\t\tDelete forever\n    Cancel -\tReturn without deleting"))
            {
                document.getElementById("frmDeleteWdRecord").submit();
            }
        }
        function submitEditForm()
        {
            document.getElementById("frmEditWd").submit();
        }
    </script>
</html>
